package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService {
    @Autowired
    private TravelCommendMapper commendMapper;

    public PageInfo<?> query(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = commendMapper.queryForList(qo);
        return new PageInfo<>(list);
    }

    public void saveOrUpdate(TravelCommend commend) {
        if (commend.getId() == null){
            commendMapper.insert(commend);
        }else {
            commendMapper.updateByPrimaryKey(commend);
        }
    }

    public PageInfo<TravelCommend> queryForApp(TravelCommendQueryObject qo) {
        qo.setOrderBy("tc.schedule desc");
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TravelCommend> list = commendMapper.queryForAppList(qo);
        return new PageInfo<>(list);
    }


}
